package com.whut.service.impl;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Matcher;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.whut.common.ReportCommonFunc;
import com.whut.mapper.NewprefixsystemMapper;

import com.whut.mapper.SummaryReportMapper;
import com.whut.model.Project;
import com.whut.service.SummaryReportService;
import com.whut.utils.pointsCalculate;
import com.whut.v_dataMap.SummaryReport.Part3VO.*;
import com.whut.v_dataMap.SummaryReport.Part3VO.LevelProblemVO.*;
import com.whut.v_dataMap.SummaryReport.Part3VO.PName4ListVO;
import com.whut.v_dataMap.SummaryReport.Part3VO.RiskDescriptionVO.RiskDescriptionTableVO;
import com.whut.v_dataMap.SummaryReport.Part3VO.RiskDescriptionVO.pName6ProblemVO;
import com.whut.utils.FileUtil;
import com.whut.utils.MDoc;
import com.whut.v_dataMap.SummaryReport.Part1.part1DataMap;
import com.whut.v_dataMap.SummaryReport.Part2.part2DataMap;
import com.whut.v_dataMap.SummaryReport.Part2.projectInfoMap;
import com.whut.v_dataMap.SummaryReport.Part3VO.XMLVO.*;
import com.whut.v_dataMap.SummaryReport.Part3VO.XMLVO.PName6ListVO;
import com.whut.v_dataMap.SummaryReport.Part4.*;
import com.whut.v_dataMap.SummaryReport.part4VO.MapTreeVO;
import com.whut.v_dataMap.SummaryReport.part4VO.ProblemVO;
import com.whut.v_vo.CalculateLevelPointVO;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.lang3.StringUtils;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.StandardBarPainter;
import org.jfree.data.category.DefaultCategoryDataset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Encoder;

import javax.annotation.Resource;
import java.awt.*;
import java.io.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SummaryReportServiceImpl implements SummaryReportService {

    @Resource
    private SummaryReportMapper summaryReportMapper;

    @Resource
    private NewprefixsystemMapper newprefixsystemMapper;

    /**
     * @author: liukang
     * @Description: 根据委托方id和时间范围查询问题信息（分子公司),用于前端页面展示
     * @date: 2020/12/25 11:01
     */
    @Override
    public List<MapTreeVO> getTaskProblemTreeInfoByIdAndTime(Integer contractId, String startTime, String endTime) {
        List<MapTreeVO> mapTreeVOList = summaryReportMapper.getTaskProblemTreeInfoByIdAndTime(contractId, startTime, endTime);
        //遍历list，即遍历分公司
        for (MapTreeVO mapTreeVOTask : mapTreeVOList) {
            //1级总问题及被选择的问题
            int childrenProblemNumTask = mapTreeVOTask.getChildren().size();
            int childrenSelectedProblemNumTask = 0;
            //遍历第一级
            for (Object mapTreeVO1 : mapTreeVOTask.getChildren()) {
                MapTreeVO mapTreeVO1New = (MapTreeVO) mapTreeVO1;
                //1级总问题及被选择的问题
                int childrenProblemNum1 = mapTreeVO1New.getChildren().size();
                int childrenSelectedProblemNum1 = 0;
                //遍历第四级
                for (Object mapTreeVO4 : mapTreeVO1New.getChildren()) {
                    MapTreeVO mapTreeVO4New = (MapTreeVO) mapTreeVO4;
                    //4级总问题及被选择的问题
                    int childrenProblemNum4 = mapTreeVO4New.getChildren().size();
                    int childrenSelectedProblemNum4 = 0;
                    //遍历第六级
                    for (Object mapTreeVO6 : mapTreeVO4New.getChildren()) {
                        MapTreeVO mapTreeVO6New = (MapTreeVO) mapTreeVO6;
                        //6级总问题及被选择的问题
                        int childrenProblemNum6 = mapTreeVO6New.getChildren().size();
                        int childrenSelectedProblemNum6 = 0;
                        //遍历第七级，即遍历问题
                        for (Object mapTreeVOProblem : mapTreeVO6New.getChildren()) {
                            ProblemVO mapTreeVOProblemNew = (ProblemVO) mapTreeVOProblem;
                            //如果此条问题被选择，则显示文本后面加（1/1）;否则（0/1）
                            if (mapTreeVOProblemNew.getIsSelected().equals("Y")) {
                                String newLabel = mapTreeVOProblemNew.getLabel() + "（1/1）";
                                mapTreeVOProblemNew.setLabel(newLabel);
                                childrenSelectedProblemNum6++;
                            } else {
                                String newLabel = mapTreeVOProblemNew.getLabel() + "（0/1）";
                                mapTreeVOProblemNew.setLabel(newLabel);
                            }
                        }
                        childrenProblemNum4 += childrenProblemNum6;
                        childrenSelectedProblemNum4 += childrenSelectedProblemNum6;
                        String newLabel6 = mapTreeVO6New.getLabel() + "（" + childrenSelectedProblemNum6 + "/" + childrenProblemNum6 + "）";
                        mapTreeVO6New.setLabel(newLabel6);
                    }
                    childrenProblemNum1 += childrenProblemNum4;
                    childrenSelectedProblemNum1 += childrenSelectedProblemNum4;
                    String newLabel4 = mapTreeVO4New.getLabel() + "（" + childrenSelectedProblemNum4 + "/" + childrenProblemNum4 + "）";
                    mapTreeVO4New.setLabel(newLabel4);
                }
                childrenProblemNumTask += childrenProblemNum1;
                childrenSelectedProblemNumTask += childrenSelectedProblemNum1;
                String newLabel1 = mapTreeVO1New.getLabel() + "（" + childrenSelectedProblemNum1 + "/" + childrenProblemNum1 + "）";
                mapTreeVO1New.setLabel(newLabel1);
            }
            String newLabelTask = mapTreeVOTask.getLabel() + "（" + childrenSelectedProblemNumTask + "/" + childrenProblemNumTask + "）";
            mapTreeVOTask.setLabel(newLabelTask);
        }
        return mapTreeVOList;
    }

    /**
     * @author: liukang
     * @Description: 根据委托方id和时间范围查询问题信息, 用于前端页面展示
     * @date: 2020/12/25 11:01
     */
    @Override
    public List<MapTreeVO> getAllProblemTreeInfoByIdAndTime(Integer contractId, String startTime, String endTime) {
        List<MapTreeVO> mapTreeVOList = summaryReportMapper.getAllProblemTreeInfoByIdAndTime(contractId, startTime, endTime);
        for (MapTreeVO mapTreeVO1 : mapTreeVOList) {
            //1级总问题及被选择的问题
            int childrenProblemNum1 = mapTreeVO1.getChildren().size();
            int childrenSelectedProblemNum1 = 0;
            //遍历第四级
            for (Object mapTreeVO4 : mapTreeVO1.getChildren()) {
                MapTreeVO mapTreeVO4New = (MapTreeVO) mapTreeVO4;
                //4级总问题及被选择的问题
                int childrenProblemNum4 = mapTreeVO4New.getChildren().size();
                int childrenSelectedProblemNum4 = 0;
                //遍历第六级
                for (Object mapTreeVO6 : mapTreeVO4New.getChildren()) {
                    MapTreeVO mapTreeVO6New = (MapTreeVO) mapTreeVO6;
                    //6级总问题及被选择的问题
                    int childrenProblemNum6 = mapTreeVO6New.getChildren().size();
                    int childrenSelectedProblemNum6 = 0;
                    //遍历第七级，即遍历问题
                    for (Object mapTreeVOProblem : mapTreeVO6New.getChildren()) {
                        ProblemVO mapTreeVOProblemNew = (ProblemVO) mapTreeVOProblem;
                        //如果此条问题被选择，则显示文本后面加（1/1）;否则（0/1）
                        if (mapTreeVOProblemNew.getIsSelected().equals("Y")) {
                            String newLabel = mapTreeVOProblemNew.getLabel() + "（1/1）";
                            mapTreeVOProblemNew.setLabel(newLabel);
                            childrenSelectedProblemNum6++;
                        } else {
                            String newLabel = mapTreeVOProblemNew.getLabel() + "（0/1）";
                            mapTreeVOProblemNew.setLabel(newLabel);
                        }
                    }
                    childrenProblemNum4 += childrenProblemNum6;
                    childrenSelectedProblemNum4 += childrenSelectedProblemNum6;
                    String newLabel6 = mapTreeVO6New.getLabel() + "（" + childrenSelectedProblemNum6 + "/" + childrenProblemNum6 + "）";
                    mapTreeVO6New.setLabel(newLabel6);
                }
                childrenProblemNum1 += childrenProblemNum4;
                childrenSelectedProblemNum1 += childrenSelectedProblemNum4;
                String newLabel4 = mapTreeVO4New.getLabel() + "（" + childrenSelectedProblemNum4 + "/" + childrenProblemNum4 + "）";
                mapTreeVO4New.setLabel(newLabel4);
            }
            String newLabel1 = mapTreeVO1.getLabel() + "（" + childrenSelectedProblemNum1 + "/" + childrenProblemNum1 + "）";
            mapTreeVO1.setLabel(newLabel1);
        }
        return mapTreeVOList;
    }

    /**
     * @author: liukang
     * @Description: 根据前端选择的图片和Mkey更新pc表
     * @date: 2020/12/25 11:01
     */
    @Override
    public int updatePCBySelectedPic(Integer Mkey, String selectedPic) {
        return summaryReportMapper.updatePCBySelectedPic(Mkey, selectedPic);
    }

    /**
     * @author: liukang
     * @Description: 重置图片选择
     * @date: 2020/12/25 11:02
     */
    @Override
    public int resetPCSelectedPic(Integer contractId, String startTime, String endTime) {
        return summaryReportMapper.resetPCSelectedPic(contractId, startTime, endTime);
    }

    /**
     * @author: liukang
     * @Description: 基于前端选择过的图片生成报告（分子公司）；分公司的版本取名task，不分公司取名all;
     * 不基于前端选择过的图片生成报告的方法后缀加All
     * @date: 2020/12/25 11:02
     */
    @Override
    public String generateTaskProblemReportInfoByIdAndTime(Integer contractId, String startTime, String endTime) {
        List<TaskMap> taskMapList = summaryReportMapper.getTaskProblemReportInfoByIdAndTime(contractId, startTime, endTime);
        if (taskMapList == null || taskMapList.size() == 0) {
            return null;
        }
        //循环计算问题数量，图片地址
        for (int i = 0; i < taskMapList.size(); i++) {
            //问题数量
            TaskMap taskMap = taskMapList.get(i);
            List<System1Map> system1List = taskMap.getSystem1List();
            //分公司下检查的项目数
            int sumProjectNumber = summaryReportMapper.getTaskCheckedProjectNumber(contractId, startTime, endTime, taskMap.getTaskName());
            taskMap.setSumProblemNum(sumProjectNumber);
            for (int j = 0; j < system1List.size(); j++) {
                //序号
                System1Map system1Map = system1List.get(j);
                system1Map.setSystem1No(ReportCommonFunc.getChineseNumber(j + 1));
                List<System4Map> system4List = system1Map.getSystem4List();
                for (int k = 0; k < system4List.size(); k++) {
                    //序号、问题数量、主要问题
                    System4Map system4Map = system4List.get(k);
                    int system4No = k + 1;
                    system4Map.setSystem4No(system4No + "");

                    //生成报告的时候，合并最后一级的问题，即相同的问题看作一条，并合并他们的图片
                    List<System7Map> oldSystem7List = system4Map.getSystem7List();
                    List<System7Map> newSystem7List = new LinkedList<>();
                    for (System7Map system7MapItem : oldSystem7List) {
                        if (!newSystem7List.contains(system7MapItem)) {
                            newSystem7List.add(system7MapItem);
                        } else {
                            for (System7Map newSystem7MapItem : newSystem7List) {
                                if (system7MapItem.equals(newSystem7MapItem)) {
                                    JSONArray newImageNameArray = JSONUtil.parseArray(newSystem7MapItem.getImageName());
                                    newImageNameArray.put(JSONUtil.parseArray(system7MapItem.getImageName()));
                                    newSystem7MapItem.setImageName(newImageNameArray.toString());
                                }
                            }
                        }
                    }
                    system4Map.setSystem7List(newSystem7List);
                    //涉及4级检查项的项目数
                    int levelFourProjectNumber = summaryReportMapper.getTaskFourCheckedProjectNumber(contractId, startTime, endTime, taskMap.getTaskName(), system4Map.getSystem4Title());
                    system4Map.setProblemNum(levelFourProjectNumber);
                    List<System7Map> system7List = system4Map.getSystem7List();
                    StringBuilder primalProblem = new StringBuilder();
                    for (int l = 0; l < system7List.size(); l++) {
                        //序号、图片
                        System7Map system7Map = system7List.get(l);
                        if (l < 3) {
                            primalProblem.append(system7Map.getProblemDescription());
                            if (l < 2) {
                                primalProblem.append("、");
                            }
                        }
                        int system7No = l + 1;
                        system7Map.setSystem7No("（" + system7No + "）");

                        List<ReportPic> imageList = new LinkedList<>();
                        JSONArray imageArray = JSONUtil.parseArray(system7Map.getImageName());
                        //处理图片，首先处理空；因为一行需要展示两张图片，所以需要对奇偶情况进行处理
                        if (imageArray == null || imageArray.size() == 0) {
                            //此处和下面处理图片编码，需要区分是本地开发还是服务器使用；
                            String s = ReportCommonFunc.generateNoPicImageCode();
                            ReportPic reportPic = new ReportPic(s, s);
                            imageList.add(reportPic);
                        } else if (imageArray.size() % 2 == 0) {
                            for (int n = 0; n < imageArray.size(); n = n + 2) {
                                String reportPic1 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageArray.get(n));
                                String reportPic2 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageArray.get(n + 1));
                                ReportPic reportPic = new ReportPic(reportPic1, reportPic2);
                                imageList.add(reportPic);
                            }
                        } else {
                            for (int n = 0; n < imageArray.size(); n = n + 2) {
                                String reportPic1 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageArray.get(n));
                                String reportPic2;
                                if (n + 1 == imageArray.size()) {
                                    reportPic2 = ReportCommonFunc.generateNoPicImageCode();
                                } else {
                                    reportPic2 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageArray.get(n + 1));
                                }
                                ReportPic reportPic = new ReportPic(reportPic1, reportPic2);
                                imageList.add(reportPic);
                            }
                        }
                        system7Map.setImageListDouble(imageList);
                    }
                    system4Map.setPrimalProblem(primalProblem.toString());
                }
            }
        }
        //根据dataMap生成报告
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
        String fileNameTime = dateTimeFormatter.format(LocalDateTime.now());
        String reportName = "问题分析报告（总报第四部分,分公司）" + fileNameTime;
        String ftlName = "SumReportPart4_TaskProblemReport";

        DataMap dataMap = new DataMap(taskMapList);
        BeanMap beanMap = new BeanMap(dataMap);

        return ReportCommonFunc.generateReport(beanMap, reportName, ftlName);
    }

    /**
     * @author: liukang
     * @Description: 基于前端选择过的图片生成报告
     * @date: 2020/12/25 11:02
     */
    @Override
    public String generateAllProblemReportInfoByIdAndTime(Integer contractId, String startTime, String endTime) {
        List<System1Map> system1List = summaryReportMapper.getAllProblemReportInfoByIdAndTime(contractId, startTime, endTime);
        //判空
        if (system1List == null || system1List.size() == 0) {
            return null;
        }
        for (int j = 0; j < system1List.size(); j++) {
            //序号
            System1Map system1Map = system1List.get(j);
            system1Map.setSystem1No(ReportCommonFunc.getChineseNumber(j + 1));
            List<System4Map> system4List = system1Map.getSystem4List();
            for (int k = 0; k < system4List.size(); k++) {
                //序号、问题数量、主要问题
                System4Map system4Map = system4List.get(k);
                int system4No = k + 1;
                system4Map.setSystem4No(system4No + "");

                //生成报告的时候，合并最后一级的问题，即相同的问题看作一条，并合并他们的图片
                List<System7Map> oldSystem7List = system4Map.getSystem7List();
                List<System7Map> newSystem7List = new LinkedList<>();
                for (System7Map system7MapItem : oldSystem7List) {
                    if (!newSystem7List.contains(system7MapItem)) {
                        newSystem7List.add(system7MapItem);
                    } else {
                        for (System7Map newSystem7MapItem : newSystem7List) {
                            if (system7MapItem.equals(newSystem7MapItem)) {
                                JSONArray newImageNameArray = JSONUtil.parseArray(newSystem7MapItem.getImageName());
                                newImageNameArray.put(JSONUtil.parseArray(system7MapItem.getImageName()));
                                newSystem7MapItem.setImageName(newImageNameArray.toString());
                            }
                        }
                    }
                }
                system4Map.setSystem7List(newSystem7List);
                //计算涉及的项目时计算
                int levelFourProjectNumber = summaryReportMapper.getAllFourCheckedProjectNumber(contractId, startTime, endTime, system4Map.getSystem4Title());
                system4Map.setProblemNum(levelFourProjectNumber);
                List<System7Map> system7List = system4Map.getSystem7List();
                StringBuilder primalProblem = new StringBuilder();
                for (int l = 0; l < system7List.size(); l++) {
                    //序号、图片
                    System7Map system7Map = system7List.get(l);
                    if (l < 3) {
                        primalProblem.append(system7Map.getProblemDescription());
                        if (l < 2) {
                            primalProblem.append("、");
                        }
                    }
                    int system7No = l + 1;
                    system7Map.setSystem7No("（" + system7No + "）");

                    List<ReportPic> imageList = new LinkedList<>();
                    JSONArray imageArray = JSONUtil.parseArray(system7Map.getImageName());
                    //处理图片，首先处理空；因为一行需要展示两张图片，所以需要对奇偶情况进行处理
                    if (imageArray == null || imageArray.size() == 0) {
                        //此处和下面处理图片编码，需要区分是本地开发还是服务器使用；
                        String s = ReportCommonFunc.generateNoPicImageCode();
                        ReportPic reportPic = new ReportPic(s, s);
                        imageList.add(reportPic);
                    } else if (imageArray.size() % 2 == 0) {
                        for (int n = 0; n < imageArray.size(); n = n + 2) {
                            String reportPic1 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageArray.get(n));
                            String reportPic2 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageArray.get(n + 1));
                            ReportPic reportPic = new ReportPic(reportPic1, reportPic2);
                            imageList.add(reportPic);
                        }
                    } else {
                        for (int n = 0; n < imageArray.size(); n = n + 2) {
                            String reportPic1 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageArray.get(n));
                            String reportPic2;
                            if (n + 1 == imageArray.size()) {
                                reportPic2 = ReportCommonFunc.generateNoPicImageCode();
                            } else {
                                reportPic2 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageArray.get(n + 1));
                            }
                            ReportPic reportPic = new ReportPic(reportPic1, reportPic2);
                            imageList.add(reportPic);
                        }
                    }
                    system7Map.setImageListDouble(imageList);
                }
                system4Map.setPrimalProblem(primalProblem.toString());
            }
        }
        //检查的项目数
        int sumProjectNumber = summaryReportMapper.getAllCheckedProjectNumber(contractId, startTime, endTime);
        SumMap dataMap = new SumMap(sumProjectNumber, system1List);
        //根据dataMap生成报告
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
        String fileNameTime = dateTimeFormatter.format(LocalDateTime.now());
        String reportName = "问题分析报告（总报第四部分）" + fileNameTime;
        String ftlName = "SumReportPart4_AllProblemReport";

        BeanMap beanMap = new BeanMap(dataMap);

        return ReportCommonFunc.generateReport(beanMap, reportName, ftlName);
    }


    /**
     * @param contractId
     * @param startTime
     * @param endTime
     * @author: liukang
     * @Description: 生成第四部分的报告(分子公司)
     * 和上面俩生成第四部分报告方法不同的地方在于没有根据前端选择过的图片生成，也就是所有图片都放进报告，所以图片由path和name拼接，而不是从selectedPic获取
     * @date: 2020/12/28 13:13
     */
    @Override
    public String generateTaskProblemReportInfoAll(Integer contractId, String startTime, String endTime) {
        List<TaskMap> taskMapList = summaryReportMapper.getTaskProblemReportInfoAll(contractId, startTime, endTime);
        if (taskMapList == null || taskMapList.size() == 0) {
            return null;
        }
        //循环计算问题数量，图片地址
        for (int i = 0; i < taskMapList.size(); i++) {
            //问题数量
            TaskMap taskMap = taskMapList.get(i);
            List<System1Map> system1List = taskMap.getSystem1List();
            //分公司下检查的项目数
            int sumProjectNumber = summaryReportMapper.getTaskCheckedProjectNumber(contractId, startTime, endTime, taskMap.getTaskName());
            taskMap.setSumProblemNum(sumProjectNumber);
            for (int j = 0; j < system1List.size(); j++) {
                //序号
                System1Map system1Map = system1List.get(j);
                system1Map.setSystem1No(ReportCommonFunc.getChineseNumber(j + 1));
                List<System4Map> system4List = system1Map.getSystem4List();
                for (int k = 0; k < system4List.size(); k++) {
                    //序号、问题数量、主要问题
                    System4Map system4Map = system4List.get(k);
                    int system4No = k + 1;
                    system4Map.setSystem4No(system4No + "");

                    //生成报告的时候，合并最后一级的问题，即相同的问题看作一条，并合并他们的图片
                    List<System7Map> oldSystem7List = system4Map.getSystem7List();
                    List<System7Map> newSystem7List = new LinkedList<>();
                    for (System7Map system7MapItem : oldSystem7List) {
                        if (!newSystem7List.contains(system7MapItem)) {
                            newSystem7List.add(system7MapItem);
                        } else {
                            for (System7Map newSystem7MapItem : newSystem7List) {
                                if (system7MapItem.equals(newSystem7MapItem)) {
                                    JSONArray newImageNameArray = JSONUtil.parseArray(newSystem7MapItem.getImageName());
                                    newImageNameArray.put(JSONUtil.parseArray(system7MapItem.getImageName()));
                                    newSystem7MapItem.setImageName(newImageNameArray.toString());
                                }
                            }
                        }
                    }
                    system4Map.setSystem7List(newSystem7List);
                    //涉及4级检查项的项目数
                    int levelFourProjectNumber = summaryReportMapper.getTaskFourCheckedProjectNumber(contractId, startTime, endTime, taskMap.getTaskName(), system4Map.getSystem4Title());
                    system4Map.setProblemNum(levelFourProjectNumber);
                    List<System7Map> system7List = system4Map.getSystem7List();
                    StringBuilder primalProblem = new StringBuilder();
                    for (int l = 0; l < system7List.size(); l++) {
                        //序号、图片
                        System7Map system7Map = system7List.get(l);
                        if (l < 3) {
                            primalProblem.append(system7Map.getProblemDescription());
                            if (l < 2) {
                                primalProblem.append("、");
                            }
                        }
                        int system7No = l + 1;
                        system7Map.setSystem7No("（" + system7No + "）");
                        //和上面方法不同的地方，获取图片的位置不同
                        List<ReportPic> imageList = new LinkedList<>();
                        JSONArray imageNameArray = JSONUtil.parseArray(system7Map.getImageName());
                        //处理图片，首先处理空；因为一行需要展示两张图片，所以需要对奇偶情况进行处理
                        if (imageNameArray == null || imageNameArray.size() == 0) {
                            //此处和下面处理图片编码，需要区分是本地开发还是服务器使用；
                            String s = ReportCommonFunc.generateNoPicImageCode();
                            ReportPic reportPic = new ReportPic(s, s);
                            imageList.add(reportPic);
                        } else if (imageNameArray.size() % 2 == 0) {
                            for (int n = 0; n < imageNameArray.size(); n = n + 2) {
                                String reportPic1 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageNameArray.get(n));
                                String reportPic2 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageNameArray.get(n + 1));
                                ReportPic reportPic = new ReportPic(reportPic1, reportPic2);
                                imageList.add(reportPic);
                            }
                        } else {
                            for (int n = 0; n < imageNameArray.size(); n = n + 2) {
                                String reportPic1 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageNameArray.get(n));
                                String reportPic2;
                                if (n + 1 == imageNameArray.size()) {
                                    reportPic2 = ReportCommonFunc.generateNoPicImageCode();
                                } else {
                                    reportPic2 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageNameArray.get(n + 1));
                                }
                                ReportPic reportPic = new ReportPic(reportPic1, reportPic2);
                                imageList.add(reportPic);
                            }
                        }
                        system7Map.setImageListDouble(imageList);
                    }
                    system4Map.setPrimalProblem(primalProblem.toString());
                }
            }
        }
        //根据dataMap生成报告
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
        String fileNameTime = dateTimeFormatter.format(LocalDateTime.now());
        String reportName = "问题分析报告（总报第四部分,分公司,所有数据版本）" + fileNameTime;
        String ftlName = "SumReportPart4_TaskProblemReport";

        DataMap dataMap = new DataMap(taskMapList);
        BeanMap beanMap = new BeanMap(dataMap);

        System.out.println("dataMap=========================>" + dataMap);

        return ReportCommonFunc.generateReport(beanMap, reportName, ftlName);
    }

    /**
     * @param contractId
     * @param startTime
     * @param endTime
     * @author: liukang
     * @Description: 生成第四部分的报告-问题分析模块
     * @date: 2020/12/28 13:13
     */
    @Override
    public String generateAllProblemReportInfoAll(Integer contractId, String startTime, String endTime) {
        List<System1Map> system1List = summaryReportMapper.getAllProblemReportInfoAll(contractId, startTime, endTime);
        //判空
        if (system1List == null || system1List.size() == 0) {
            return null;
        }
        for (int j = 0; j < system1List.size(); j++) {
            //序号
            System1Map system1Map = system1List.get(j);
            system1Map.setSystem1No(ReportCommonFunc.getChineseNumber(j + 1));
            List<System4Map> system4List = system1Map.getSystem4List();
            for (int k = 0; k < system4List.size(); k++) {
                //序号、问题数量、主要问题
                System4Map system4Map = system4List.get(k);
                int system4No = k + 1;
                system4Map.setSystem4No(system4No + "");

                //生成报告的时候，合并最后一级的问题，即相同的问题看作一条，并合并他们的图片
                List<System7Map> oldSystem7List = system4Map.getSystem7List();
                List<System7Map> newSystem7List = new LinkedList<>();
                for (System7Map system7MapItem : oldSystem7List) {
                    if (!newSystem7List.contains(system7MapItem)) {
                        newSystem7List.add(system7MapItem);
                    } else {
                        for (System7Map newSystem7MapItem : newSystem7List) {
                            if (system7MapItem.equals(newSystem7MapItem)) {
                                JSONArray newImageNameArray = JSONUtil.parseArray(newSystem7MapItem.getImageName());
                                newImageNameArray.put(JSONUtil.parseArray(system7MapItem.getImageName()));
                                newSystem7MapItem.setImageName(newImageNameArray.toString());
                            }
                        }
                    }
                }
                system4Map.setSystem7List(newSystem7List);
                //计算涉及的项目时计算
                int levelFourProjectNumber = summaryReportMapper.getAllFourCheckedProjectNumber(contractId, startTime, endTime, system4Map.getSystem4Title());
                system4Map.setProblemNum(levelFourProjectNumber);
                List<System7Map> system7List = system4Map.getSystem7List();
                StringBuilder primalProblem = new StringBuilder();
                for (int l = 0; l < system7List.size(); l++) {
                    //序号、图片
                    System7Map system7Map = system7List.get(l);
                    if (l < 3) {
                        primalProblem.append(system7Map.getProblemDescription());
                        if (l < 2) {
                            primalProblem.append("、");
                        }
                    }
                    int system7No = l + 1;
                    system7Map.setSystem7No("（" + system7No + "）");
                    //和上面方法不同的地方，获取图片的位置不同
                    List<ReportPic> imageList = new LinkedList<>();
                    JSONArray imageNameArray = JSONUtil.parseArray(system7Map.getImageName());
                    //处理图片，首先处理空；因为一行需要展示两张图片，所以需要对奇偶情况进行处理
                    if (imageNameArray == null || imageNameArray.size() == 0) {
                        //此处和下面处理图片编码，需要区分是本地开发还是服务器使用；
                        String s = ReportCommonFunc.generateNoPicImageCode();
                        ReportPic reportPic = new ReportPic(s, s);
                        imageList.add(reportPic);
                    } else if (imageNameArray.size() % 2 == 0) {
                        for (int n = 0; n < imageNameArray.size(); n = n + 2) {
                            String reportPic1 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageNameArray.get(n));
                            String reportPic2 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageNameArray.get(n + 1));
                            ReportPic reportPic = new ReportPic(reportPic1, reportPic2);
                            imageList.add(reportPic);
                        }
                    } else {
                        for (int n = 0; n < imageNameArray.size(); n = n + 2) {
                            String reportPic1 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageNameArray.get(n));
                            String reportPic2;
                            if (n + 1 == imageNameArray.size()) {
                                reportPic2 = ReportCommonFunc.generateNoPicImageCode();
                            } else {
                                reportPic2 = ReportCommonFunc.generateImageCode(system7Map.getImagePath() + imageNameArray.get(n + 1));
                            }
                            ReportPic reportPic = new ReportPic(reportPic1, reportPic2);
                            imageList.add(reportPic);
                        }
                    }
                    system7Map.setImageListDouble(imageList);
                }
                system4Map.setPrimalProblem(primalProblem.toString());
            }
        }
        //检查的项目数
        int sumProjectNumber = summaryReportMapper.getAllCheckedProjectNumber(contractId, startTime, endTime);
        SumMap dataMap = new SumMap(sumProjectNumber, system1List);
        //根据dataMap生成报告
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
        String fileNameTime = dateTimeFormatter.format(LocalDateTime.now());
        String reportName = "问题分析报告（总报第四部分,所有数据版本）" + fileNameTime;
        String ftlName = "SumReportPart4_AllProblemReport";

        BeanMap beanMap = new BeanMap(dataMap);

        return ReportCommonFunc.generateReport(beanMap, reportName, ftlName);
    }

    /**
     * @param contractId
     * @param startTime
     * @param endTime
     * @author: liukang
     * @Description: 生成封面
     * @date: 2021/1/15 21:10
     */
    @Override
    public String generateCoverReport(Integer contractId, String startTime, String endTime) {

        //年、月
        LocalDate localDate = LocalDate.now();
        DateTimeFormatter dateFormatterYear = DateTimeFormatter.ofPattern("yyyy");
        String year = dateFormatterYear.format(localDate);
        int month = localDate.getMonthValue();

        //季度
        String season = "";
        switch (((month - 1) / 3) + 1) {
            case 1:
                season = "一";
                break;
            case 2:
                season = "二";
                break;
            case 3:
                season = "三";
                break;
            case 4:
                season = "四";
                break;
        }

        String contractName = summaryReportMapper.getContractNameByContractId(contractId);

        com.whut.v_dataMap.SummaryReport.Cover.DataMap dataMap = new com.whut.v_dataMap.SummaryReport.Cover.DataMap(year, contractName, season, month);

        //根据dataMap生成报告
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
        String fileNameTime = dateTimeFormatter.format(LocalDateTime.now());
        String reportName = "报告封面（总报封面部分）" + fileNameTime;
        String ftlName = "SumReportPart0_Cover";

        BeanMap beanMap = new BeanMap(dataMap);

        return ReportCommonFunc.generateReport(beanMap, reportName, ftlName);
    }


    /**
     * @author wangqirui
     * @create 2021/1/27 下午 5:15
     * @desc 生成安全总报一部分 检查评估综述
     **/
    @Override
    public String generatePart1Report(Integer contractId, String startTime, String endTime, List<Double> amPoint) {
        //查出projectInfo
        List<projectInfoMap> projectInfoList = summaryReportMapper.getProjectInfoBycontractIdandTime(contractId, startTime, endTime);
        List<ProjectListVO> scProjectList = getPart3BasicData(contractId, startTime, endTime, 1);
        List<ProjectListVO> qrProjectList = getPart3BasicData(contractId, startTime, endTime, 628);


        //计算scPoint（安全文明）的值
        for (int i = 0; i < projectInfoList.size(); i++) {
            for (int j = 0; j < scProjectList.size(); j++) {
                if (projectInfoList.get(i).getProjectId() == scProjectList.get(j).getProjectId()) {
                    projectInfoList.get(i).setScPoint(scProjectList.get(j).getSum());
                    break;
                }
            }
        }


        //计算qrPoint（质量风险）的值
        for (int i = 0; i < projectInfoList.size(); i++) {
            for (int j = 0; j < qrProjectList.size(); j++) {
                if (projectInfoList.get(i).getProjectId() == qrProjectList.get(j).getProjectId()) {
                    projectInfoList.get(i).setQrPoint(qrProjectList.get(j).getSum());
                    break;
                }
            }
        }


        //计算eqPoint（工程质量），eqPoint = 0.6 * qrPoint + 0.4 * amPoint
        double eqPoint = 0.00f;
        for (int i = 0; i < projectInfoList.size(); i++) {
            //amPoint.add(i, 1.0);
            projectInfoList.get(i).setAmPoint(amPoint.get(i));
            eqPoint = (0.6 * (projectInfoList.get(i).getQrPoint())) + (0.4 * (amPoint.get(i)));
            projectInfoList.get(i).setEqPoint(eqPoint);
        }

        //计算综合得分（overallPoint）
        double overallPoint = 0;
        for (int i = 0; i < projectInfoList.size(); i++) {
            overallPoint = ((projectInfoList.get(i).getScPoint()) + (projectInfoList.get(i).getQrPoint()) + (projectInfoList.get(i).getAmPoint()) + (projectInfoList.get(i).getEqPoint())) / 4;
            projectInfoList.get(i).setOverallPoint(overallPoint);
        }

        //按综合得分降序排序得到排序后的List（SortedprojectInfoList）
        List<projectInfoMap> SortedprojectInfoList = projectInfoList.stream().sorted((Comparator.comparing(projectInfoMap::getOverallPoint)).reversed()).collect(Collectors.toList());

        //Removing items that point is 0 in SortedprojectInfoList
        for (int i = 0; i < SortedprojectInfoList.size(); i++) {
            if (SortedprojectInfoList.get(i).getScPoint() == 0 || SortedprojectInfoList.get(i).getQrPoint() == 0 || SortedprojectInfoList.get(i).getAmPoint() == 0 || SortedprojectInfoList.get(i).getEqPoint() == 0) {
                SortedprojectInfoList.remove(i--);
            }
        }


        //统计标段数量
        int bidNum = projectInfoList.size();


        //算出平均数
        Double avgoverallPoint = SortedprojectInfoList.stream().mapToDouble(projectInfoMap::getOverallPoint).average().getAsDouble();


        //统计低于平均数的值和百分比
        int count = 0;
        while (SortedprojectInfoList.get(count).getOverallPoint() > avgoverallPoint) {
            count++;
        }
        int udavgBidNum = SortedprojectInfoList.size() - count;
        double per = ((double) udavgBidNum / (double) bidNum) * 100;
        String udavgBidNumPer = String.valueOf(per) + '%';


        //统计最好和最差的数据
        String topProjectName = SortedprojectInfoList.get(0).getProjectName();
        double topProjectPoint = SortedprojectInfoList.get(0).getOverallPoint();
        String lastProjectName = SortedprojectInfoList.get(SortedprojectInfoList.size() - 1).getProjectName();
        double lastProjectPoint = SortedprojectInfoList.get(SortedprojectInfoList.size() - 1).getOverallPoint();


        //getContractNameByContractId
        String contractName = summaryReportMapper.getContractNameByContractId(contractId);

        part1DataMap dataMap = new com.whut.v_dataMap.SummaryReport.Part1.part1DataMap(contractName, bidNum, udavgBidNum, udavgBidNumPer, topProjectName, topProjectPoint, lastProjectName, lastProjectPoint, avgoverallPoint);


        //根据dataMap生成报告
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
        String fileNameTime = dateTimeFormatter.format(LocalDateTime.now());
        String reportName = "检查评估综述（总报第一部分）" + fileNameTime;
        String ftlName = "SumReportPart1_Review";

        BeanMap beanMap = new BeanMap(dataMap);
        return ReportCommonFunc.generateReport(beanMap, reportName, ftlName);

    }

    /**
     * @author wangqirui
     * @create 2021/1/27 下午 5:15
     * @desc 生成projectInfo, 给前端以获取ampoint实测实量分数
     **/
    @Override
    public List<projectInfoMap> generateProjectInfo(Integer contractId, String startTime, String endTime) {
        List<projectInfoMap> list = summaryReportMapper.getProjectInfoBycontractIdandTime(contractId, startTime, endTime);
        return list;
    }


    /**
     * @author wangqirui
     * @create 2021/1/27 下午 5:15
     * @desc 生成安全总报二部分 综合评分情况模块
     **/
    @Override
    public String generatePart2Report(Integer contractId, String startTime, String endTime, List<Double> amPoint) {
        //查出projectInfo
        List<projectInfoMap> projectInfoList = summaryReportMapper.getProjectInfoBycontractIdandTime(contractId, startTime, endTime);
        List<ProjectListVO> scProjectList = getPart3BasicData(contractId, startTime, endTime, 1);
        List<ProjectListVO> qrProjectList = getPart3BasicData(contractId, startTime, endTime, 628);


        //计算scPoint（安全文明）的值
        for (int i = 0; i < projectInfoList.size(); i++) {
            for (int j = 0; j < scProjectList.size(); j++) {
                if (projectInfoList.get(i).getProjectId() == scProjectList.get(j).getProjectId()) {
                    projectInfoList.get(i).setScPoint(scProjectList.get(j).getSum());
                    break;
                }
            }
        }


        //计算qrPoint（质量风险）的值
        for (int i = 0; i < projectInfoList.size(); i++) {
            for (int j = 0; j < qrProjectList.size(); j++) {
                if (projectInfoList.get(i).getProjectId() == qrProjectList.get(j).getProjectId()) {
                    projectInfoList.get(i).setQrPoint(qrProjectList.get(j).getSum());
                    break;
                }
            }
        }


        //计算eqPoint（工程质量），eqPoint = 0.6 * qrPoint + 0.4 * amPoint
        double eqPoint = 0.00f;
        for (int i = 0; i < projectInfoList.size(); i++) {
            //amPoint.add(i, 1.0);
            projectInfoList.get(i).setAmPoint(amPoint.get(i));
            eqPoint = (0.6 * (projectInfoList.get(i).getQrPoint())) + (0.4 * (amPoint.get(i)));
            projectInfoList.get(i).setEqPoint(eqPoint);
        }


        //计算综合得分（overallPoint）
        double overallPoint = 0;

        for (int i = 0; i < projectInfoList.size(); i++) {
            overallPoint = ((projectInfoList.get(i).getScPoint()) + (projectInfoList.get(i).getQrPoint()) + (projectInfoList.get(i).getAmPoint()) + (projectInfoList.get(i).getEqPoint())) / 4;
            projectInfoList.get(i).setOverallPoint(overallPoint);
        }


        //按综合得分降序排序得到排序后的List（SortedprojectInfoList）
        List<projectInfoMap> SortedprojectInfoList = projectInfoList.stream().sorted((Comparator.comparing(projectInfoMap::getOverallPoint)).reversed()).collect(Collectors.toList());

        //Removing items that point is 0 in SortedprojectInfoList
        for (int i = 0; i < SortedprojectInfoList.size(); i++) {
            if (SortedprojectInfoList.get(i).getScPoint() == 0 || SortedprojectInfoList.get(i).getQrPoint() == 0 || SortedprojectInfoList.get(i).getAmPoint() == 0 || SortedprojectInfoList.get(i).getEqPoint() == 0) {
                SortedprojectInfoList.remove(i--);
            }
        }


        //统计标段数量
        int bidNum = projectInfoList.size();


        //将projectInfiList拆分成土建项目（landConstructionList）与商业项目（commercialList），并添加上序号（no）
        List<projectInfoMap> landConstructionList = new ArrayList<>();
        List<projectInfoMap> commercialList = new ArrayList<>();
        int j = 0, k = 0;
        for (int i = 0; i < SortedprojectInfoList.size(); i++) {
            if (SortedprojectInfoList.get(i).getProjectType().equals("商业")) {
                commercialList.add(j, SortedprojectInfoList.get(i));
                commercialList.get(j).setNo(++j);
            } else {
                landConstructionList.add(k, SortedprojectInfoList.get(i));
                landConstructionList.get(k).setNo(++k);
            }
        }


        //算出各项平均数
        Double avgscPoint = SortedprojectInfoList.stream().mapToDouble(projectInfoMap::getScPoint).average().getAsDouble();
        Double avgqrPoint = SortedprojectInfoList.stream().mapToDouble(projectInfoMap::getQrPoint).average().getAsDouble();
        Double avgamPoint = SortedprojectInfoList.stream().mapToDouble(projectInfoMap::getAmPoint).average().getAsDouble();
        Double avgeqPoint = SortedprojectInfoList.stream().mapToDouble(projectInfoMap::getEqPoint).average().getAsDouble();
        Double avgoverallPoint = SortedprojectInfoList.stream().mapToDouble(projectInfoMap::getOverallPoint).average().getAsDouble();


        //设置生成报告所需数据
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
        String fileNameTime = dateTimeFormatter.format(LocalDateTime.now());
        String reportName = "综合评分情况（总报第二部分）" + fileNameTime;
        String ftlName = "SumReportPart2_OverallPoint";


        //打印综合评分直方图 （columnKey和bar有些错位）
        DefaultCategoryDataset datasetBar = new DefaultCategoryDataset();
        datasetBar.addValue(avgamPoint, "100", "实测实量       ");
        datasetBar.addValue(avgqrPoint, "200", "质量风险    ");
        datasetBar.addValue(avgeqPoint, "300", "  工程质量");
        datasetBar.addValue(avgscPoint, "400", "       安全文明");
        try {
            JFreeChart barChart = ChartFactory.createBarChart("华中区域过程评估分项综合评分直方图",
                    "",
                    "",
                    datasetBar,
                    PlotOrientation.VERTICAL,
                    false, false, false);

            barChart.getTitle().setFont(new Font("黑体", Font.BOLD, 16));//设置标题文字
            CategoryPlot plot = (CategoryPlot) barChart.getPlot();
            plot.getRenderer().setSeriesPaint(0, new Color(51, 153, 255));
            plot.getRenderer().setSeriesPaint(1, new Color(51, 153, 255));
            plot.getRenderer().setSeriesPaint(2, new Color(51, 153, 255));
            plot.getRenderer().setSeriesPaint(3, new Color(51, 153, 255));
            BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
            barRenderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
            barRenderer.setDefaultItemLabelsVisible(true);
            barRenderer.setItemMargin(-0.5);//设置柱子间隔
            barRenderer.setDefaultOutlinePaint(Color.WHITE);//
            barRenderer.setDrawBarOutline(true);
            barRenderer.setBarPainter(new StandardBarPainter());
            NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
            numberAxis.setTickLabelFont(new Font("黑体", Font.BOLD, 14));// 纵坐标y轴坐标字体
            numberAxis.setUpperBound(100);//设置最大值的显示问题
            CategoryAxis categoryAxis = (CategoryAxis) plot.getDomainAxis();
            categoryAxis.setTickLabelFont(new Font("黑体", Font.BOLD, 14));// 横坐标x轴坐标字体
            //线上使用
            File barChartFile = new File("D:\\whutServer\\generatedCharts\\" + fileNameTime + "overAllPointBarChart.png");
            //线下测试使用
            //File barChartFile = new File("D:\\研究生文件\\毅瑞项目\\测试的报告文件\\测试要用的图片\\" + fileNameTime + "overAllPointBarChart.png");
            ChartUtils.saveChartAsPNG(barChartFile, barChart, 718, 468);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //线上使用
        String logoUrl = getImgFileToBase64("D:\\whutServer\\generatedCharts\\" + fileNameTime + "overAllPointBarChart.png");
        //线下测试使用
        //String logoUrl = getImgFileToBase64("D:\\研究生文件\\毅瑞项目\\测试的报告文件\\测试要用的图片\\" + fileNameTime + "overAllPointBarChart.png");


        //根据datamap生成报告
        com.whut.v_dataMap.SummaryReport.Part2.part2DataMap dataMap = new com.whut.v_dataMap.SummaryReport.Part2.part2DataMap(bidNum,
                avgscPoint, avgqrPoint, avgamPoint, avgeqPoint, avgoverallPoint, logoUrl, landConstructionList, commercialList);
        BeanMap beanMap = new BeanMap(dataMap);

        return ReportCommonFunc.generateReport(beanMap, reportName, ftlName);
    }

    public static String getImgFileToBase64(String imgFile) {
        //将图片文件转化为字节数组字符串，并对其进行Base64编码处理
        InputStream inputStream = null;
        byte[] buffer = null;
        //读取图片字节数组
        try {
            inputStream = new FileInputStream(imgFile);
            int count = 0;
            while (count == 0) {
                count = inputStream.available();
            }
            buffer = new byte[count];
            inputStream.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    // 关闭inputStream流
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        // 对字节数组Base64编码
        return new BASE64Encoder().encode(buffer);
    }


    /**
     * @author： wenyihan
     * @description：生成第三部分基础数据
     * @date： 19:33 2021/1/27
     */
    @Override
    public List<ProjectListVO> getPart3BasicData(Integer contractId, String startTime, String endTime, Integer firstId) {
        List<ProjectListVO> list = summaryReportMapper.getPart3BasicData(contractId, startTime, endTime, firstId);

        for (ProjectListVO project : list) {
            for (CheckListVO check : project.getCheckList()) {
                for (PName1ListVO pName1 : check.getpName1List()) {
                    List<CalculateLevelPointVO> point1Ca = new ArrayList<>();
                    for (PName2ListVO pName2 : pName1.getpName2List()) {
                        List<CalculateLevelPointVO> point2Ca = new ArrayList<>();
                        for (PName3ListVO pName3 : pName2.getpName3List()) {
                            //附加扣分直接在point1Ca中扣除，不参与体系分数计算
                            if (pName3.getPoint3().equals("0")) {
                                break;
                            }
                            List<CalculateLevelPointVO> point3Ca = new ArrayList<>();
                            for (PName4ListVO pName4 : pName3.getpName4List()) {
                                //附加扣分直接在point1Ca中扣除，不参与体系分数计算
                                if (pName4.getPoint4().equals("0")) {
                                    break;
                                }
                                List<CalculateLevelPointVO> point4Ca = new ArrayList<>();
                                for (PName5ListVO pName5 : pName4.getpName5List()) {
                                    //附加扣分直接在point1Ca中扣除，不参与体系分数计算
                                    if (pName5.getPoint5().equals("0")) {
                                        break;
                                    }
                                    List<CalculateLevelPointVO> point5Ca = new ArrayList<>();
                                    for (com.whut.v_dataMap.SummaryReport.Part3VO.PName6ListVO pName6 : pName5.getpName6List()) {
                                        //附加扣分直接在point1Ca中扣除，不参与体系分数计算
                                        if (pName6.getPoint6().equals("0")) {
                                            break;
                                        }
                                        int index = 1;
                                        for (ProblemListVO problem : pName6.getProblemList()) {
                                            //计算point6
                                            Double point6D = 0d;
                                            String reducePoint = "";
                                            //todo pcd表里有problemNum、problemQua、deductPoint为空的检查项，有问题，为出报告，被迫这样写。之后请修复数据库数据！！！！
                                            if (StringUtils.contains(problem.getDeductPoint(), ";")) {
                                                reducePoint = pointsCalculate.getReducePoint(problem.getProblemNum(), problem.getProblemQua(), problem.getDeductPoint());
                                            } else {
                                                reducePoint = problem.getDeductPoint();
                                            }

                                            point6D = index == 1
                                                    ? pointSubtract(pName6.getPoint6(), reducePoint)
                                                    : pointSubtract(pName6.getPoint6Ca(), reducePoint);
                                            if (point6D >= 0d) {
                                                pName6.setPoint6Ca(point6D.toString());
                                            } else {
                                                pName6.setPoint6Ca("0");
                                                break;
                                            }
                                            index++;
                                        }
                                        //将计算point5所需数据加入CalculateLevelPointVO类型的List
                                        CalculateLevelPointVO ca5 = new CalculateLevelPointVO(pName6.getWeight6(), pName6.getPoint6(), pName6.getPoint6Ca());
                                        point5Ca.add(ca5);
                                    }
                                    //计算point5
                                    String point5 = pointsCalculate.calculatePoint(point5Ca, pName5.getPoint5());
                                    pName5.setPoint5Ca(point5);
                                    //将计算point4所需数据加入CalculateLevelPointVO类型的List
                                    CalculateLevelPointVO ca4 = new CalculateLevelPointVO(pName5.getWeight5(), pName5.getPoint5(), pName5.getPoint5Ca());
                                    point4Ca.add(ca4);
                                }
                                //计算point4
                                String point4 = pointsCalculate.calculatePoint(point4Ca, pName4.getPoint4());
                                pName4.setPoint4Ca(point4);
                                //将计算point3所需数据加入CalculateLevelPointVO类型的List
                                CalculateLevelPointVO ca3 = new CalculateLevelPointVO(pName4.getWeight4(), pName4.getPoint4(), pName4.getPoint4Ca());
                                point3Ca.add(ca3);
                            }
                            //计算point3
                            String point3 = pointsCalculate.calculatePoint(point3Ca, pName3.getPoint3());
                            pName3.setPoint3Ca(point3);
                            //将计算point2所需数据加入CalculateLevelPointVO类型的List
                            CalculateLevelPointVO ca2 = new CalculateLevelPointVO(pName3.getWeight3(), pName3.getPoint3(), pName3.getPoint3Ca());
                            point2Ca.add(ca2);
                        }
                        //计算point2
                        String point2 = pointsCalculate.calculatePoint(point2Ca, pName2.getPoint2());
                        pName2.setPoint2Ca(point2);
                        //将计算point1所需数据加入CalculateLevelPointVO类型的List
                        CalculateLevelPointVO ca1 = new CalculateLevelPointVO(pName2.getWeight2(), pName2.getPoint2(), pName2.getPoint2Ca());
                        point1Ca.add(ca1);
                    }
                    //计算point1
                    String point1 = pointsCalculate.calculatePoint(point1Ca, pName1.getPoint1());
                    if (!StrUtil.isBlankIfStr(pName1.getExtraReduce())) {
                        Double temp = this.pointSubtract(point1, pName1.getExtraReduce());
                        point1 = String.valueOf(temp);
                    }
                    pName1.setPoint1Ca(point1);
                }
                List<PName1ListVO> pName1List = check.getpName1List();
                Double point1Sum = pName1List.stream()
                        .mapToDouble(x -> Double.parseDouble(x.getPoint1Ca()))
                        .average()
                        .orElse(0D);
                check.setPoint1Sum(point1Sum);
            }
            List<CheckListVO> checkList = project.getCheckList();
            Double sum = checkList.stream()
                    .mapToDouble(CheckListVO::getPoint1Sum)
                    .average()
                    .orElse(0D);
            project.setSum(sum);
        }

        return list;
    }

    /**
     * @author： wenyihan
     * @description：获取A\B\C类问题的结论,①riskBasicData：每项第四级对应的问题数量+换算后所占比例；②levelList：a/b/c类包含的第四级名称
     * @date： 18:49 2021/1/27
     * @param： [contractId, startTime, endTime, firstId]
     * @return： java.util.Map<java.lang.String, java.util.List>
     */
    @Override
    public Map<String, List> getLevelConclusion(Integer contractId, String startTime, String endTime, Integer firstId) {
        Map<String, List> dataMap = new HashMap<>();
        List<RiskProblemNumSumVO> riskProblemSum = new ArrayList<>();
        List<RiskpName4VO> getPName4AndRiskNum = summaryReportMapper.getPName4AndRiskNum(contractId, startTime, endTime, firstId);
        List<LevelProblemListVO> levelProblemList = new ArrayList<>();
        //计算转换比例的问题数量
        int totalNum = 0;
        //计算所有问题数量
        int totalRiskNum = 0;
        List<String> levelA = new ArrayList<>();
        List<String> levelB = new ArrayList<>();
        List<String> levelC = new ArrayList<>();

        RiskProblemNumSumVO riskSum = new RiskProblemNumSumVO();
        int risk1Num = 0, risk2Num = 0, risk3Num = 0, risk4Num = 0;
        for (RiskpName4VO risk : getPName4AndRiskNum) {
            for (RiskPName6VO pName6 : risk.getpName6List()) {
                totalRiskNum += pName6.getRiskPoint().size();
                for (RiskProblemVO problem : pName6.getRiskPoint()) {
                    switch (problem.getRiskPoint()) {
                        case "提醒":
                        case "1":
                            risk1Num++;
                            break;
                        case "2":
                            risk2Num++;
                            break;
                        case "3":
                            ++totalNum;
                            risk3Num++;
                            break;
                        case "4":
                            totalNum += 5;
                            risk4Num++;
                            break;
                    }
                }
            }
        }
        riskSum.setRisk1Num(risk1Num);
        riskSum.setRisk2Num(risk2Num);
        riskSum.setRisk3Num(risk3Num);
        riskSum.setRisk4Num(risk4Num);
        riskSum.setTotalRiskNum(totalRiskNum);
        riskSum.setRisk1NumPercent((double) risk1Num / (double) totalRiskNum * 100d);
        riskSum.setRisk2NumPercent((double) risk2Num / (double) totalRiskNum * 100d);
        riskSum.setRisk3NumPercent((double) risk3Num / (double) totalRiskNum * 100d);
        riskSum.setRisk4NumPercent((double) risk4Num / (double) totalRiskNum * 100d);

        List<RiskProblemNumVO> riskProblemNum = new ArrayList<>();
        for (RiskpName4VO risk : getPName4AndRiskNum) {
            double percentCalculate = 0d;
            risk1Num = 0; risk2Num = 0; risk3Num = 0; risk4Num = 0;
            RiskProblemNumVO riskProblemNumMap = new RiskProblemNumVO();
            riskProblemNumMap.setpName4(risk.getpName4());
            for (RiskPName6VO pName6 : risk.getpName6List()) {
                //计算各类问题数量
                for (RiskProblemVO problem : pName6.getRiskPoint()) {
                    switch (problem.getRiskPoint()) {
                        case "提醒":
                        case "1":
                            risk1Num++;
                            break;
                        case "2":
                            risk2Num++;
                            break;
                        case "3":
                            risk3Num++;
                            break;
                        case "4":
                            risk4Num++;
                            break;
                    }
                }
            }
            riskProblemNumMap.setAllRiskNum(risk1Num + risk2Num + risk3Num + risk4Num);
            riskProblemNumMap.setRisk1Num(risk1Num);
            riskProblemNumMap.setRisk2Num(risk2Num);
            riskProblemNumMap.setRisk3Num(risk3Num);
            riskProblemNumMap.setRisk4Num(risk4Num);
            //重大隐患按1:5折算成较大隐患数据
            int biggerRiskNum = risk4Num * 5 + risk3Num;
            riskProblemNumMap.setBiggerRiskNum(biggerRiskNum);
            //计算折算后所占比例
            percentCalculate = ((double) biggerRiskNum / (double) totalNum * 100d);
            riskProblemNumMap.setPercent(percentCalculate);
            riskProblemNum.add(riskProblemNumMap);
        }
        //根据占比排序
        riskProblemNum = riskProblemNum.stream()
                .sorted(Comparator.comparing(RiskProblemNumVO::getPercent).reversed())
                .collect(Collectors.toList());
        riskSum.setRiskProblemNumList(riskProblemNum);
        riskProblemSum.add(riskSum);

        //归类为A/B/C类
        double percent = 0d;
        for (RiskProblemNumVO obj : riskProblemNum) {
            percent += obj.getPercent();
            if (percent <= 80d) {
                levelA.add(obj.getpName4());
            } else if (percent > 80d && percent <= 90d) {
                levelB.add(obj.getpName4());
            } else {
                levelC.add(obj.getpName4());
            }
        }

        LevelProblemListVO levelAList = new LevelProblemListVO("levelA", levelA);
        levelProblemList.add(levelAList);
        LevelProblemListVO levelBList = new LevelProblemListVO("levelB", levelB);
        levelProblemList.add(levelBList);
        LevelProblemListVO levelCList = new LevelProblemListVO("levelC", levelC);
        levelProblemList.add(levelCList);

        dataMap.put("riskBasicData", riskProblemSum);
        dataMap.put("levelList", levelProblemList);
        return dataMap;
    }

    public Double pointSubtract(String x, String y) {
        Double res = Double.parseDouble(x) - Double.parseDouble(y);
        return res;
    }

    /**
     * @author： wenyihan
     * @description：返回表格数据
     * @date： 18:58 2021/1/30
     * @param： [contractId, startTime, endTime]
     * @return： com.whut.v_dataMap.SummaryReport.Part3VO.RankTableVO
     */
    @Override
    public RankTableVO getRankTableData(Integer contractId, String startTime, String endTime, Integer firstId) {
        //获取基本数据
        List<ProjectListVO> basicData = this.getPart3BasicData(contractId, startTime, endTime, firstId);
        RankTableVO tableData = new RankTableVO();
        //整合所有片区
        List<String> taskDescription = new ArrayList<>();
        List<RankTableInnerPartVO> innerPartList = new ArrayList<>();
        //存储所有的pName4和fourthId
        List<RankTablePName4ListVO> allpName4List = new ArrayList<>();
        for (ProjectListVO project : basicData) {
            //每check数据都是表格一行数据
            RankTableInnerPartVO innerPartMap = new RankTableInnerPartVO();
            //获取项目名称
            innerPartMap.setProjectName(project.getProjectName());
            //获取第四级及其分数
            List<RankTablePName4PartVO> pName4List = new ArrayList<>();
            for (CheckListVO check : project.getCheckList()) {
                if (!taskDescription.contains(check.getTaskDescription())) {
                    taskDescription.add(check.getTaskDescription());
                }

                for (PName1ListVO pName1 : check.getpName1List()) {
                    //获取第一级名称
                    tableData.setpName1(pName1.getpName1());
                    for (PName2ListVO pName2 : pName1.getpName2List()) {
                        for (PName3ListVO pName3 : pName2.getpName3List()) {
                            for (PName4ListVO pName4 : pName3.getpName4List()) {
                                if (StrUtil.isBlankIfStr(pName4.getPoint4Ca())) {
                                    break;
                                }
                                //获取每个项目的第四级及其对应分数
                                RankTablePName4PartVO pName4Map = new RankTablePName4PartVO();
                                pName4Map.setFourthId(pName4.getFourthId());
                                pName4Map.setPoint(pName4.getPoint4Ca());
                                pName4List.add(pName4Map);
                                //获取所有的pName4
                                RankTablePName4ListVO allpName4ListMap = new RankTablePName4ListVO();
                                allpName4ListMap.setpName4(pName4.getpName4());
                                allpName4ListMap.setFourthId(pName4.getFourthId());
                                if (!allpName4List.contains(allpName4ListMap)) {
                                    allpName4List.add(allpName4ListMap);
                                }
                            }

                        }
                    }
                }
            }
            List<RankTablePName4PartVO> reducedPName4List = new ArrayList<>();
            //合并相同第四级分数
            pName4List.parallelStream()
                    .collect(Collectors.groupingBy(o -> o.getFourthId(), Collectors.toList())).forEach(
                    (id, item) -> {
                        item.stream()
                                .reduce((x, y) -> new RankTablePName4PartVO(x.getFourthId(), String.valueOf(Double.parseDouble(x.getPoint()) + Double.parseDouble(y.getPoint()) / 2)))
                                .ifPresent(reducedPName4List::add);
                    }
            );
            innerPartMap.setpName4List(reducedPName4List);
            innerPartMap.setSum(project.getSum());
            innerPartList.add(innerPartMap);
        }

        tableData.setpName4List(allpName4List);
        //逆序排序
        innerPartList = innerPartList.stream()
                .sorted(Comparator.comparing(RankTableInnerPartVO::getSum).reversed())
                .collect(Collectors.toList());
        tableData.setInnerPartList(innerPartList);
        tableData.setTaskDescription(taskDescription);

        for (RankTablePName4ListVO rankTablePName4ListVO : tableData.getpName4List()) {
            int fourthId = rankTablePName4ListVO.getFourthId();
            Double sumPoint = 0d;
            int num = 0;
            for (RankTableInnerPartVO rankTableInnerPartVO : tableData.getInnerPartList()) {
                for (RankTablePName4PartVO rankTablePName4PartVO : rankTableInnerPartVO.getpName4List()) {
                    if (rankTablePName4PartVO.getFourthId() == fourthId) {
                        sumPoint += Double.parseDouble(rankTablePName4PartVO.getPoint());
                        num++;
                    }
                }
            }
            if (num != 0) {
                sumPoint = sumPoint / num;
            }
            BigDecimal bigDecimal = new BigDecimal(sumPoint);
            Double sumPointNew = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            rankTablePName4ListVO.setAveragePoint(sumPointNew);
        }

        return tableData;
    }

    /**
     * @author： wenyihan
     * @description：返回隐患分布表格
     * @date： 15:07 2021/1/31
     * @param： [contractId, startTime, endTime, firstId]
     * @return： java.util.List<com.whut.v_dataMap.SummaryReport.Part3VO.RiskDescriptionVO.RiskDescriptionTableVO>
     */
    @Override
    public List<RiskDescriptionTableVO> getRiskDescription(Integer contractId, String startTime, String endTime, Integer firstId) {
        List<RiskDescriptionTableVO> riskDescriptionTableInfo = new ArrayList<>();
        List<RiskpName4VO> table = summaryReportMapper.getPName4AndRiskNum(contractId, startTime, endTime, firstId);
        for (RiskpName4VO pName4 : table) {
            RiskDescriptionTableVO tableData = new RiskDescriptionTableVO();
            //计算检查项目数量
            Integer checkProjectNum = summaryReportMapper.getCheckProjectNum(contractId, startTime, endTime, firstId);
            tableData.setCheckProjectNum(checkProjectNum);
            //计算涉及项目数量
            Integer hadProblemProjectNum = summaryReportMapper.hadProblemProjectNum(contractId, startTime, endTime, firstId, pName4.getFourthId());
            tableData.setHadProblemProjectNum(hadProblemProjectNum);
            //获取pName4
            tableData.setpName4(pName4.getpName4());
            //获取第四级id
            tableData.setFourthId(pName4.getFourthId());
            //获取问题分类及问题数量
            List<pName6ProblemVO> pName6ProblemList = new ArrayList<>();
            for (RiskPName6VO pName6 : pName4.getpName6List()) {
                pName6ProblemVO pName6Problem = new pName6ProblemVO();
                pName6Problem.setpName6(pName6.getpName6());
                pName6Problem.setpName6ProblemNum(pName6.getRiskPoint().size());
                pName6Problem.setHavingRisk4("no");
                int risk1Num = 0, risk2Num = 0, risk3Num = 0, risk4Num = 0;
                for (RiskProblemVO last : pName6.getRiskPoint()) {
                    switch (last.getRiskPoint()) {
                        case "提醒":
                        case "1":
                            risk1Num++;
                            break;
                        case "2":
                            risk2Num++;
                            break;
                        case "3":
                            risk3Num++;
                            break;
                        case "4":
                            risk4Num++;
                            pName6Problem.setHavingRisk4("yes");
                            break;
                    }
                }
                pName6Problem.setRisk1Num(risk1Num);
                pName6Problem.setRisk2Num(risk2Num);
                pName6Problem.setRisk3Num(risk3Num);
                pName6Problem.setRisk4Num(risk4Num);
                pName6ProblemList.add(pName6Problem);
            }
            tableData.setpName6ProblemList(pName6ProblemList);
            riskDescriptionTableInfo.add(tableData);
        }
        return riskDescriptionTableInfo;
    }

    /**
     * @author： wenyihan
     * @description：总报第三部分总体
     * @date： 12:20 2021/2/2
     * @param： [contractId, startTime, endTime, levelAProblemList, levelBProblemList, levelCProblemList, sameProblem, specialProblem, suggestion]
     * @return： com.whut.v_dataMap.SummaryReport.Part3VO.XMLVO.SummaryReportPart3
     */
    @Override
    public String getSummaryReportPart3(Integer contractId, String startTime, String endTime, ReportDataVO reportData) {
        List<EvaluateSuggestionListVO> evaluateSuggestionList = reportData.getEvaluateSuggestionList();
        List<LevelConclusionListVO> levelConclusionList = reportData.getLevelConclusionList();
        List<RiskDescriptionListVO> riskDescriptionList = reportData.getRiskDescriptionList();

        SummaryReportPart3 dataMap = new SummaryReportPart3();
        //一、获取委托方姓名
        String contractName = summaryReportMapper.getContractNameByContractId(contractId);
        dataMap.setContractName(contractName);

        //二、获取片区名称
        String taskDescription = "";
        //查询所有涉及的pName1
        List<Integer> firstIdList = summaryReportMapper.getFirstIdByContractIdAndTimeRange(contractId, startTime, endTime);
        for (Integer firstId : firstIdList) {
            //1、根据firstId获取片区名称
            List<ProjectListVO> getPName1Info = this.getPart3BasicData(contractId, startTime, endTime, firstId);
            for (ProjectListVO project : getPName1Info) {
                for (CheckListVO check : project.getCheckList()) {
                    taskDescription += check.getTaskDescription() + "、";
                }
            }
        }
        //2、处理字符串最后字符
        taskDescription = taskDescription.substring(0, taskDescription.length() - 1);
        dataMap.setTaskDescriptionList(taskDescription);

        //三、检查总结
        int index = 1;
        List<CheckSummaryListVO> checkSummaryList = new ArrayList<>();
        for (Integer firstId : firstIdList) {
            //标号
            CheckSummaryListVO summaryMap = new CheckSummaryListVO();
            String part1Index = ReportCommonFunc.getChineseNumber(index);
            summaryMap.setIndex(part1Index);
            ++index;
            //pName1
            String pName1 = newprefixsystemMapper.getName4ByName4Id(firstId);
            summaryMap.setpName1(pName1);

            /*与levelA\B\C有关的字段*/
            Map<String, List> getLevelInfo = this.getLevelConclusion(contractId, startTime, endTime, firstId);
            List<RiskProblemNumSumVO> riskProblemSum = getLevelInfo.get("riskBasicData");
            for (RiskProblemNumSumVO risk : riskProblemSum) {
                //提醒+1、2、3、4 特征值的数量
                summaryMap.setProblemNum(risk.getTotalRiskNum());
                summaryMap.setRisk1AndTXNum(risk.getRisk1Num());
                summaryMap.setRisk2Num(risk.getRisk2Num());
                summaryMap.setRisk3Num(risk.getRisk3Num());
                summaryMap.setRisk4Num(risk.getRisk4Num());
                summaryMap.setRisk3Percent(risk.getRisk3NumPercent());
                String levelA1 = risk.getRiskProblemNumList().get(0).getpName4();
                Double levelA1Percent = risk.getRiskProblemNumList().get(0).getPercent();
                summaryMap.setLevelA1(levelA1);
                summaryMap.setLevelA1Percent(levelA1Percent);
                String riskProblemDetail = "";
                for (RiskProblemNumVO riskNum : risk.getRiskProblemNumList()) {
                    riskProblemDetail += riskNum.getpName4() + "隐患问题" + riskNum.getAllRiskNum() + ",";
                }
                riskProblemDetail = riskProblemDetail.substring(0, riskProblemDetail.length() - 1);
                summaryMap.setRiskProblemDetail(riskProblemDetail);
            }
            List<LevelProblemListVO> levelList = getLevelInfo.get("levelList");
            String levelA = "", levelB = "", levelC = "";
            for (LevelProblemListVO level : levelList) {
                switch (level.getLevel()) {
                    case "levelA":
                        for (String str : level.getpName4()) {
                            levelA += str + "、";
                        }
                        break;
                    case "levelB":
                        for (String str : level.getpName4()) {
                            levelB += str + "、";
                        }
                        break;
                    case "levelC":
                        for (String str : level.getpName4()) {
                            levelC += str + "、";
                        }
                        break;
                }
            }

            levelA = levelA.substring(0, levelA.length() - 1);
            levelB = levelB.substring(0, levelB.length() - 1);
            levelC = levelC.substring(0, levelC.length() - 1);
            summaryMap.setLevelA(levelA);
            summaryMap.setLevelB(levelB);
            summaryMap.setLevelC(levelC);

            List<com.whut.v_dataMap.SummaryReport.Part3VO.XMLVO.PName4ListVO> pName4List = new ArrayList<>();
            List<RiskDescriptionTableVO> riskDescription = this.getRiskDescription(contractId, startTime, endTime, firstId);
            for (RiskDescriptionTableVO riskDes : riskDescription) {
                String havingRisk4 = "";
                com.whut.v_dataMap.SummaryReport.Part3VO.XMLVO.PName4ListVO pName4Map = new com.whut.v_dataMap.SummaryReport.Part3VO.XMLVO.PName4ListVO();
                pName4Map.setpName4(riskDes.getpName4());
                List<PName6ListVO> pName6List = new ArrayList<>();
                for (pName6ProblemVO pName6 : riskDes.getpName6ProblemList()) {
                    PName6ListVO pName6Map = new PName6ListVO();
                    pName6Map.setpName4(riskDes.getpName4());
                    pName6Map.setCheckProjectNum(riskDes.getCheckProjectNum());
                    pName6Map.setHadProblemProjectNum(riskDes.getHadProblemProjectNum());
                    pName6Map.setpName6(pName6.getpName6());
                    pName6Map.setpName6ProblemNum(pName6.getpName6ProblemNum());
                    if (pName6.getHavingRisk4().equals("yes")) {
                        havingRisk4 += pName6.getpName6() + "、";
                    }
                    for (RiskDescriptionListVO risk : riskDescriptionList) {
                        if (risk.getFirstId().equals(firstId)) {
                            for (RiskDescriptionVO problem : risk.getRiskDescription()) {
                                if (problem.getFourthId().equals(riskDes.getFourthId())) {
                                    String sameProblem = String.join(",", problem.getCommonProblem());
                                    String specialProblem = String.join(",", problem.getIndividualProblem());
                                    pName6Map.setSameProblem(sameProblem);
                                    pName6Map.setSpecialProblem(specialProblem);
                                }
                            }
                        }
                    }
                    pName6List.add(pName6Map);
                }
                pName4Map.setHadProblemProjectNum(riskDes.getHadProblemProjectNum());
                pName4Map.setpName6List(pName6List);
                pName4Map.setRisk4Problem(havingRisk4);
                pName4List.add(pName4Map);
            }
            summaryMap.setpName4List(pName4List);
            //获取levelA/B/CProblemList
            String levelAproblemList = "";
            String levelBproblemList = "";
            String levelCproblemList = "";
            for (LevelConclusionListVO level : levelConclusionList) {
                if (level.getFirstId().equals(firstId)) {
                    for (LevelConclusionVO levelConclusion : level.getLevelConclusion()) {
                        switch (levelConclusion.getLevel()) {
                            case "levelA":
                                for (PName4DangerVO danger : levelConclusion.getpName4Danger()) {
                                    levelAproblemList += danger.getpName4() + "(" + danger.getDanger() + ")、";
                                }
                                break;
                            case "levelB":
                                for (PName4DangerVO danger : levelConclusion.getpName4Danger()) {
                                    levelBproblemList += danger.getpName4() + "(" + danger.getDanger() + ")、";
                                }
                                break;
                            case "levelC":
                                for (PName4DangerVO danger : levelConclusion.getpName4Danger()) {
                                    levelCproblemList += danger.getpName4() + "(" + danger.getDanger() + ")、";
                                }
                                break;
                        }
                    }
                }
            }
            summaryMap.setLevelAProblemList(levelAproblemList);
            summaryMap.setLevelBProblemList(levelBproblemList);
            summaryMap.setLevelCProblemList(levelCproblemList);

            checkSummaryList.add(summaryMap);
        }
        dataMap.setCheckSummaryList(checkSummaryList);

        //四、检查评估
        index = 1;
        List<CheckSuggestionListVO> checkSuggestionList = new ArrayList<>();
        for (Integer firstId : firstIdList) {
            //标号
            CheckSuggestionListVO suggestionMap = new CheckSuggestionListVO();
            String part2Index = ReportCommonFunc.getChineseNumber(index);
            suggestionMap.setPart2Index(part2Index);
            ++index;
            //pName1
            String pName1 = newprefixsystemMapper.getName4ByName4Id(firstId);
            suggestionMap.setpName1(pName1);
            for (EvaluateSuggestionListVO evaluate : evaluateSuggestionList) {
                if (evaluate.getFirstId().equals(firstId)) {
                    suggestionMap.setSuggestion(evaluate.getEvaluateSuggestion());
                }
            }
            checkSuggestionList.add(suggestionMap);
        }
        dataMap.setCheckSuggestionList(checkSuggestionList);

        //根据dataMap生成报告
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
        String fileNameTime = dateTimeFormatter.format(LocalDateTime.now());
        String reportName = "第三部分 过程评估检查总结与建议" + fileNameTime;
        String ftlName = "SumReportPart3_SummaryAndSuggestion";

        BeanMap beanMap = new BeanMap(dataMap);

        return ReportCommonFunc.generateReport(beanMap, reportName, ftlName);
    }

    /**
     * @author: liukang
     * @Description: 获取所有第一级检查
     * @date: 2021/2/2 21:46
     */
    @Override
    public List<Level1IdAndNameVO> getLevel1IdAndName(Integer contractId, String startTime, String endTime) {
        return summaryReportMapper.getLevel1IdAndName(contractId, startTime, endTime);

    }

}
